﻿using System;
using System.Data.Entity.Design;
using System.Data.Metadata.Edm;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using EntityFrameworkContrib.Design.VisualStudio.Testing.Mock;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace EntityFrameworkContrib.Design.VisualStudio.Testing
{
	/// <summary>
	/// Summary description for PluginManagerTests
	/// </summary>
	[TestClass]
	public class PluginManagerTests
	{
		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get { return testContextInstance; }
			set { testContextInstance = value; }
		}	TestContext testContextInstance;

		[TestInitialize]
		public void InitializeTest()
		{
			MockCodeGenerator.Subscribed = false;
			MockCodeGenerator.Items.Clear();
		}

		[TestMethod, DeploymentItem( "SampleModel.edmx" )]
		public void VerifyMockCodeGeneratorRegistered()
		{
			Assert.IsFalse( MockCodeGenerator.Subscribed );
			string path = Path.GetFullPath( "SampleModel.edmx" ),
				content = File.ReadAllText( path );

			Parser parser = new Parser();
			string code = parser.Parse( content );

			Assert.IsNotNull( code );
			Assert.IsTrue( MockCodeGenerator.Subscribed );
		}

		[TestMethod, DeploymentItem( "SampleModel.edmx" )]
		public void VerifyMockCodeGeneratorOnTypeGeneratedCalled()
		{
			Assert.AreEqual( 0, MockCodeGenerator.Items.Count );
			string path = Path.GetFullPath( "SampleModel.edmx" ),
				content = File.ReadAllText( path );

			Parser parser = new Parser();
			parser.Parse( content );

			Assert.AreEqual( 3, MockCodeGenerator.Items.Count );
		}
	}
}
